#include "Ray.h"

Ray::Ray(void)
{
}

Ray::Ray( Point3* o, Vector3* d )
{
	origin = new Point3(o);
	tMin = EPSILON;
	tMax = POSITIVE_INFINITY;
	direction = new Vector3(d);
	direction->normalize();
}

Ray::Ray( Point3* a, Point3* b )
{
	origin = new Point3(a);
	tMin = EPSILON;
	direction = Point3::sub(b, a, new Vector3());
	tMax = direction->length() - EPSILON;
	direction->normalize();
}
Ray::~Ray(void)
{
}

double Ray::getMin()
{
	return tMin;
}

double Ray::getMax()
{
	return tMax;
}

Point3* Ray::getOrigin()
{
	return origin;
}

Vector3* Ray::getDirection()
{
	return direction;
}

bool Ray::isEmpty()
{
	return tMax <= tMin;
}

bool Ray::isInside( double t )
{
	return tMin <= t && t <= tMax;
}

Point3* Ray::getPoint( double t, Point3* dest )
{
	dest->x = origin->x + t * direction->x;
	dest->y = origin->y + t * direction->y;
	dest->z = origin->z + t * direction->z;
	return dest;
}

void Ray::setMinMax( double min, double max )
{
	tMin = min;
	tMax = max;
}

void Ray::setMin( double t )
{
	if (t > tMin)
		tMin = t;
}

void Ray::setMax( double t )
{
	if (t < tMax)
		tMax = t;
}